package utils;

import javax.servlet.http.HttpSession;

import model.User;


public class LoggedUser extends User
{
	
	public enum UserType
	{
		guest, registered
	}
	
	
	private static final String userKey = "LoggedUser";
	

	private UserType type;
	
	public LoggedUser(User user,UserType type)
	{
		this.setUsername(user.getUsername());
		this.setStatus(user.getStatus());
		this.setPassword(user.getPassword());
		this.setId(user.getId());
		this.type=type;
	}

	public static LoggedUser getUser(HttpSession session)
	{
		LoggedUser user = (LoggedUser) session.getAttribute(userKey);

		return user;
	}
	
	public static void setUser(HttpSession session, LoggedUser user)
	{
		session.setAttribute(userKey, user);
	}

	public static String getUserkey()
	{
		return userKey;
	}

	public UserType getType()
	{
		return type;
	}
	
	public static boolean isLogged(HttpSession session)
	{
		if(getUser(session) == null)
		{
			return false;
		}
		else
		{
			return true;
		}
	}

}
